﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.BLL/TableManager
* 类       名: TableManager
* 功      能:  数据库表管理类,主要用来创建和管理数据库的表
* 时      间:  2023/6/20 17:10:09
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using SiliconSelect.Base;
using SiliconSelect.Common;
using SiliconSelect.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SiliconSelect.BLL
{

    public class TableManager
    {
        public static DataResult CreateTotalTables()
        {
            DataResult result = new DataResult();
            try
            {
                // 1. 创建UserTable表
                CreateUserTable();
                CreateWorkingInfoTable();
                CreateModuleShieldStateTable();
                CreateSlaveSettingTable();
                CreateCrystalLevelCountTable();
                CreateBoxesStateTable();
                CreateAlarmShowTable();
                CreateAlarmRecordTable();
                CreateAlarmSettingTable();
                CreateCrystalResultRecordTable();
                CreateVisionOffsetTable();
                CreateWaferDetectedDetailTable(GlobalValues.CrystalNumberCurrent!);
                result.State = true;
                result.Data = "所有的表都创建成功!";
            }
            catch (Exception ex)
            {
                result.Message = ExceptionHelper.GetFullException(ex, MethodBase.GetCurrentMethod()!);
            }
            return result;
        }

        /// <summary>
        /// 自动创建用户表
        /// </summary>
        private static void CreateUserTable()
        {
            string tableName = TableNames.UserTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                 $"BEGIN " +
                                 $"CREATE TABLE[dbo].[{tableName}](" +
                                 $"[UserId] INT IDENTITY(1,1) PRIMARY KEY," +
                                 $"[UserName] VARCHAR(50) NOT NULL," +
                                 $"[Password] VARCHAR(50) NOT NULL," +
                                 $"[Role] VARCHAR(50) NOT NULL," +
                                 $"[CreateBy] VARCHAR(50) NOT NULL," +
                                 $"[CreateTime] VARCHAR(50) NOT NULL," +
                                 $"[LastLoginTime] VARCHAR(50) NOT NULL);" +
                                 $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条Admin用户管理员数据!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([Username], [Password],[Role],[CreateBy],[CreateTime],[LastLoginTime]) " +
                        $"VALUES (@username,@password,@role,@createBy,@createTime,@lastLoginTime)";
                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@username",SqlDbType.VarChar){Value = "admin"},
                        new SqlParameter("@password",SqlDbType.VarChar){Value="admin"},
                        new SqlParameter("@role",SqlDbType.VarChar){Value="工程师"},
                        new SqlParameter("@createBy",SqlDbType.VarChar){Value="System"},
                        new SqlParameter("@createTime",SqlDbType.VarChar){Value= DateTimeHelper.GetTimeNowForSql()},
                        new SqlParameter("@lastLoginTime",SqlDbType.VarChar){Value=DateTimeHelper.GetTimeNowForSql()},
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 自动创建当前作业的信息表
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateWorkingInfoTable()
        {
            string tableName = TableNames.WorkingInfoTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                 $"BEGIN " +
                                 $"CREATE TABLE[dbo].[{tableName}](" +
                                  $"[WorkingId] INT IDENTITY(1,1) PRIMARY KEY," +
                                 $"[FlowerNumber] VARCHAR(100)," +
                                 $"[ProductionDate] VARCHAR(100) NOT NULL," +
                                 $"[CutNumber] VARCHAR(100) NOT NULL," +
                                 $"[CrystalNumber] VARCHAR(100) NOT NULL," +
                                 $"[TheoryCounts]  VARCHAR(100) NULL," +
                                 $"[TotalCountFromPc] VARCHAR(100) NOT NULL," +
                                 $"[PositionNumber] VARCHAR(100) NOT NULL," +
                                 $"[ProductionLot] VARCHAR(100)," +
                                 $"[ProductionRecipe] VARCHAR(200) NOT NULL," +
                                 $"[RecipeImportDir] VARCHAR(200) NOT NULL," +
                                 $"[RecipeImportFile] VARCHAR(200) NOT NULL," +
                                 $"[LastCrystalNumber] VARCHAR(100) );" +
                                 $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([FlowerNumber], [ProductionDate],[CutNumber],[CrystalNumber]," +
                        $"[TheoryCounts],[TotalCountFromPc],[PositionNumber],[ProductionLot],[ProductionRecipe],[RecipeImportDir],[RecipeImportFile],[LastCrystalNumber]) " +
                        $"VALUES (@FlowerNumber,@ProductionDate,@CutNumber,@CrystalNumber,@TheoryCounts,@TotalCountFromPc," +
                        $"@PositionNumber,@ProductionLot,@ProductionRecipe,@RecipeImportDir,@RecipeImportFile,@LastCrystalNumber)";
                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@FlowerNumber",SqlDbType.VarChar){Value = "No1"},
                        new SqlParameter("@ProductionDate",SqlDbType.VarChar){Value="2023年06月25日 白班(08:00-20:00)"},
                        new SqlParameter("@CutNumber",SqlDbType.VarChar){Value = "Test001"},
                        new SqlParameter("@CrystalNumber",SqlDbType.VarChar){Value="Test001"},
                        new SqlParameter("@TheoryCounts",SqlDbType.Int){Value = "4000"},
                        new SqlParameter("@TotalCountFromPc",SqlDbType.Int){Value="0"},
                        new SqlParameter("@PositionNumber",SqlDbType.VarChar){Value ="1"},
                        new SqlParameter("@ProductionLot",SqlDbType.VarChar){Value="Lot1"},
                        new SqlParameter("@ProductionRecipe",SqlDbType.VarChar){Value=@"DefaultRecipe.xlsx"},
                        new SqlParameter("@RecipeImportDir",SqlDbType.VarChar){Value = @"C:\Users\geym\Desktop\机台配方"},
                        new SqlParameter("@RecipeImportFile",SqlDbType.VarChar){Value = @"DefaultRecipe.xlsx"},
                        new SqlParameter("@LastCrystalNumber", SqlDbType.VarChar) { Value = "JY-16-230308-0032-0-E06" }
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 创建模块屏蔽表,用来保存模块的屏蔽状态.
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateModuleShieldStateTable()
        {
            string tableName = TableNames.ModuleShieldStateTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[ModuleName] VARCHAR(100)," +
                                    $"[IsShielded] bit NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入默认数据
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入几条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([ModuleName], [IsShielded]) " +
                        $"VALUES (@Name1,@IsShield1), (@Name2,@IsShield2), (@Name3,@IsShield3)," +
                        $"(@Name4,@IsShield4),(@Name5,@IsShield5),(@Name6,@IsShield6)," +
                        $" (@Name7,@IsShield7), (@Name8,@IsShield8), (@Name9,@IsShield9),(@Name10,@IsShield10);";

                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@Name1",SqlDbType.VarChar){Value = "电阻率"},
                        new SqlParameter("@IsShield1",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name2",SqlDbType.VarChar){Value = "尺寸"},
                        new SqlParameter("@IsShield2",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name3",SqlDbType.VarChar){Value = "前崩"},
                        new SqlParameter("@IsShield3",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name4",SqlDbType.VarChar){Value = "后崩"},
                        new SqlParameter("@IsShield4",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name5",SqlDbType.VarChar){Value = "左崩"},
                        new SqlParameter("@IsShield5",SqlDbType.Bit){Value=true },

                        new SqlParameter("@Name6",SqlDbType.VarChar){Value = "右崩"},
                        new SqlParameter("@IsShield6",SqlDbType.Bit){Value=true },

                        new SqlParameter("@Name7",SqlDbType.VarChar){Value = "上脏污"},
                        new SqlParameter("@IsShield7",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name8",SqlDbType.VarChar){Value = "下脏污"},
                        new SqlParameter("@IsShield8",SqlDbType.Bit){Value=true },

                        new SqlParameter("@Name9",SqlDbType.VarChar){Value = "隐裂"},
                        new SqlParameter("@IsShield9",SqlDbType.Bit){Value=false },

                        new SqlParameter("@Name10",SqlDbType.VarChar){Value = "3D"},
                        new SqlParameter("@IsShield10",SqlDbType.Bit){Value=false },
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 创建SlaveSetting(从站设置表)
        /// 这些表主要是用来保存从站的名称,从站的IP地址,还有端口号信息.
        /// 后续可能还会有增加,目前先这样.
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateSlaveSettingTable()
        {
            string tableName = TableNames.SlaveSettingTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[SlaveName] VARCHAR(100)," +
                                    $"[SlaveIp] VARCHAR(100) NOT NULL," +
                                    $"[SlavePort] int NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入几条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([SlaveName], [SlaveIp],[SlavePort]) " +
                        $"VALUES (@SlaveName1,@SlaveIp1,@SlavePort1),(@SlaveName2,@SlaveIp2,@SlavePort2)," +
                        $"(@SlaveName3,@SlaveIp3,@SlavePort3),(@SlaveName4,@SlaveIp4,@SlavePort4)," +
                        $"(@SlaveName5,@SlaveIp5,@SlavePort5);";
                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@SlaveName1",SqlDbType.VarChar){Value = "1. 电阻率"},
                        new SqlParameter("@SlaveIp1",SqlDbType.VarChar){Value = "192.168.3.101"},
                        new SqlParameter("@SlavePort1",SqlDbType.Int){Value= 50001},

                        new SqlParameter("@SlaveName2",SqlDbType.VarChar){Value = "2. 尺寸"},
                        new SqlParameter("@SlaveIp2",SqlDbType.VarChar){Value = "192.168.0.102"},
                        new SqlParameter("@SlavePort2",SqlDbType.Int){Value= 5001},

                        new SqlParameter("@SlaveName3",SqlDbType.VarChar){Value = "3. 崩边隐裂"},
                        new SqlParameter("@SlaveIp3",SqlDbType.VarChar){Value = "192.168.3.103"},
                        new SqlParameter("@SlavePort3",SqlDbType.Int){Value= 5004},

                        new SqlParameter("@SlaveName4",SqlDbType.VarChar){Value = "4. 3D"},
                        new SqlParameter("@SlaveIp4",SqlDbType.VarChar){Value = "192.168.3.104"},
                        new SqlParameter("@SlavePort4",SqlDbType.Int){Value= 5002},

                        new SqlParameter("@SlaveName5",SqlDbType.VarChar){Value = "5. 脏污"},
                        new SqlParameter("@SlaveIp5",SqlDbType.VarChar){Value = "192.168.3.105"},
                        new SqlParameter("@SlavePort5",SqlDbType.Int){Value= 5003},
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 创建晶棒统计表,根据晶棒编号去统计对应的类型以及对应等级的个数
        /// </summary>
        private static void CreateCrystalLevelCountTable()
        {
            string tableName = TableNames.CrystalLevelCountTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[CrystalNumber] VARCHAR(100)," +
                                    $"[LevelIndex] INT NOT NULL," +
                                    $"[LevelType] VARCHAR(100) NOT NULL," +
                                    $"[Count] VARCHAR(100) NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([CrystalNumber], [LevelIndex],[LevelType],[Count]) " +
                        $"VALUES (@CrystalNumber,@LevelIndex,@LevelType,@Count);";
                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@CrystalNumber",SqlDbType.VarChar){Value = "TestData"},
                        new SqlParameter("@LevelIndex",SqlDbType.VarChar){Value = 0},
                        new SqlParameter("@LevelType",SqlDbType.VarChar){Value= "0.测试数据"},
                        new SqlParameter("@Count",SqlDbType.VarChar){Value="0" }
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 料盒状态表
        /// </summary>
        private static void CreateBoxesStateTable()
        {
            string tableName = TableNames.BoxesStateTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[BoxNumber] VARCHAR(50) NOT NULL," +
                                    $"[LevelType] VARCHAR(100) NOT NULL," +
                                    $"[CountMax] VARCHAR(100) NULL," +
                                    $"[Count] VARCHAR(100) NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([BoxNumber], [LevelType],[CountMax],[Count]) " +
                        $"VALUES (@BoxNumber,@LevelType,@CountMax,@Count);";

                    for (int i = 1; i <= 19; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@BoxNumber",SqlDbType.Int){Value = i.ToString()},
                            new SqlParameter("@LevelType",SqlDbType.VarChar){Value = ""},
                            new SqlParameter("@CountMax",SqlDbType.VarChar){Value= "200"},
                            new SqlParameter("@Count",SqlDbType.VarChar){Value="0"}
                        };
                        int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        if (ret <= 0)
                        {
                            infoMessage = $"数据表{tableName} 插入数据失败!";
                            throw new Exception(infoMessage);
                        }
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 创建报警设置表
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateAlarmSettingTable()
        {
            string tableName = TableNames.AlarmSettingTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[AlarmCode] VARCHAR(50) ," +
                                    $"[Content] VARCHAR(300) ," +
                                    $"[SolutionHelp] VARCHAR(300));" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([AlarmCode], [Content],[SolutionHelp]) " +
                        $"VALUES (@AlarmCode,@Content,@SolutionHelp);";

                    for (int i = 0; i < 0; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@AlarmCode",SqlDbType.VarChar){Value = "1"},
                            new SqlParameter("@Content",SqlDbType.VarChar){Value= "报警测试"},
                            new SqlParameter("@SolutionHelp",SqlDbType.VarChar){Value="解决方式测试"},
                        };
                        int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        if (ret <= 0)
                        {
                            infoMessage = $"数据表{tableName} 插入数据失败!";
                            throw new Exception(infoMessage);
                        }
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 创建报警信息表
        /// </summary>
        private static void CreateAlarmRecordTable()
        {
            string tableName = TableNames.AlarmRecordTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)

                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                  $"BEGIN " +
                                  $"CREATE TABLE[dbo].[{tableName}](" +
                                  $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                  $"[AlarmCode] VARCHAR(50) ," +
                                  $"[Content] VARCHAR(300) ," +
                                  $"[SolutionHelp] VARCHAR(300)," +
                                  $"[CreateTime] VARCHAR(50));" +
                                  $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([AlarmCode],[Content],[SolutionHelp],[CreateTime]) " +
                        $"VALUES (@AlarmCode,@Content,@SolutionHelp,@CreateTime);";

                    for (int i = 0; i < 0; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@AlarmCode",SqlDbType.VarChar){Value = "P00"},
                            new SqlParameter("@Content",SqlDbType.VarChar){Value= "这是一个测试示例"},
                            new SqlParameter("@SolutionHelp",SqlDbType.VarChar){Value="这是一个测试示例的解决方案"},
                            new SqlParameter("@CreateTime",SqlDbType.VarChar){Value= DateTimeHelper.GetTimeNowForSql()}
                        };
                        int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        if (ret <= 0)
                        {
                            infoMessage = $"数据表{tableName} 插入数据失败!";
                            throw new Exception(infoMessage);
                        }
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        private static void CreateAlarmShowTable()
        {
            string tableName = TableNames.AlarmMainShowTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)

                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                  $"BEGIN " +
                                  $"CREATE TABLE[dbo].[{tableName}](" +
                                  $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                  $"[AlarmCode] VARCHAR(50) ," +
                                  $"[Content] VARCHAR(300) ," +
                                  $"[SolutionHelp] VARCHAR(300)," +
                                  $"[CreateTime] VARCHAR(50));" +
                                  $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count < 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([AlarmCode],[Content],[SolutionHelp],[CreateTime]) " +
                        $"VALUES (@AlarmCode,@Content,@SolutionHelp,@CreateTime);";

                    for (int i = 0; i < 1; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@AlarmCode",SqlDbType.VarChar){Value = "P00"},
                            new SqlParameter("@Content",SqlDbType.VarChar){Value= "这是一个测试示例"},
                            new SqlParameter("@SolutionHelp",SqlDbType.VarChar){Value="这是一个测试示例"},
                            new SqlParameter("@CreateTime",SqlDbType.VarChar){Value= DateTimeHelper.GetTimeNowForSql()}
                        };
                        int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        if (ret <= 0)
                        {
                            infoMessage = $"数据表{tableName} 插入数据失败!";
                            throw new Exception(infoMessage);
                        }
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    // 如果存在数据,就清空
                    sql = $"Truncate Table {tableName} ";
                    SqlHelper.ExecuteNonQuery(sql, null);
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表存在内容,清空报警内容成功!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        public static string GetTableNameByCrystalNumber(string crystalName)
        {
            try
            {
                crystalName = crystalName.Replace("-", "").Trim();
                return crystalName;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogType.Exception, ExceptionHelper.GetFullException(ex, MethodBase.GetCurrentMethod()!));
                return "DefaultCystalName";
            }
        }

        /// <summary>
        /// 硅片检测详细信息表
        /// </summary>
        /// <exception cref="Exception"></exception>
        public static void CreateWaferDetectedDetailTable(string crystalName)
        {
            string tableName = GetTableNameByCrystalNumber(crystalName);
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] BIGINT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[DetectedTime] VARCHAR(50) DEFAULT ' '," +               // 操作时间
                                    $"[ProductionDate] VARCHAR(200) DEFAULT ' '," +               // 生产日期班班次
                                    $"[WaferId] VARCHAR(50) DEFAULT ' '," +                         // 产品Id
                                    $"[CutNumber] VARCHAR(100) DEFAULT ' '," +                 // 切割编号
                                    $"[CrystalNumber] VARCHAR(100) DEFAULT ' '," +          //  晶棒编号
                                    $"[PositionNumber] VARCHAR(100) DEFAULT ' '," +         // 位置编号
                                    $"[ProductionLot] VARCHAR(100) DEFAULT ' '," +           //  生产批次
                                    $"[FlowerNumber] VARCHAR(100) DEFAULT ' '," +           // 花篮号
                                    $"[DetectionRecipe] VARCHAR(100) DEFAULT ' '," +         // 检测配方
                                    $"[DetectedLevel] VARCHAR(100) DEFAULT ' '," +            // 检测等级
                                    $"[LevelType] VARCHAR(100) DEFAULT ' '," +                   // 等级类型
                                    $"[TypeDescription] VARCHAR(100) DEFAULT ' '," +        // 类型描述
                                    $"[BoxNumber] VARCHAR(100) DEFAULT ' '," +                // 入选料盒
                                    $"[ThicknessAver] VARCHAR(100) DEFAULT ' '," +          //  平均厚度
                                    $"[TTV] VARCHAR(100) DEFAULT ' '," +                            //  TTV
                                    $"[LineTraceMax] VARCHAR(100) DEFAULT ' '," +           //  线痕最大值
                                    $"[Warping] VARCHAR(100) DEFAULT ' '," +                     //  翘曲
                                    $"[ThicknessMin] VARCHAR(100) DEFAULT ' '," +           //  最小厚度
                                    $"[ThicknessMax] VARCHAR(100) DEFAULT ' '," +          //   最大厚度
                                    $"[IsDenseLine] VARCHAR(20) DEFAULT ' '," +               //   是否密集线痕
                                    $"[LineTraceUpNum] VARCHAR(100) DEFAULT ' '," +     //   上线痕数量
                                    $"[LineTraceUpMax] VARCHAR(100) DEFAULT ' '," +      //   上线痕数量最大值
                                    $"[LineTraceDownNum] VARCHAR(100) DEFAULT ' '," +  //   下线痕数量
                                    $"[LineTraceDownMax] VARCHAR(100) DEFAULT ' '," +  //   下线痕数量最大值
                                    $"[LineTraceCount] VARCHAR(100) DEFAULT ' '," +        // 线痕数量
                                    $"[ResistivityAver] VARCHAR(100) DEFAULT ' '," +        // 电阻率
                                    $"[ResistivityMax] VARCHAR(100) DEFAULT ' '," +        // 电阻率最大值
                                    $"[ResistivityMin] VARCHAR(100) DEFAULT ' '," +        //  电阻率最小值
                                    $"[LengthMax] VARCHAR(100) DEFAULT ' '," +              //  边长最大值
                                    $"[LengthMin] VARCHAR(100) DEFAULT ' '," +              // 边长最小值
                                    $"[LengthX] VARCHAR(100) DEFAULT ' '," +                  // X边长
                                    $"[LengthY] VARCHAR(100) DEFAULT ' '," +                  // Y边长
                                    $"[DiagonalLeftStart] VARCHAR(100) DEFAULT ' '," +  // 对角线左上右下
                                    $"[DialonalRightStart] VARCHAR(100) DEFAULT ' '," + // 对角线左下右上
                                    $"[ChamferMax] VARCHAR(100) DEFAULT ' '," +          //  倒角最大值
                                    $"[ChamferMin] VARCHAR(100) DEFAULT ' '," +          // 倒角最小值
                                    $"[UpDownParallel] VARCHAR(100) DEFAULT ' '," +    // 上下平行度
                                    $"[LeftRightParallel] VARCHAR(100) DEFAULT ' '," +  // 左右平行度
                                    $"[SquareLineMax] VARCHAR(100) DEFAULT ' '," +  // 直角边最大值
                                    $"[SquareLineMin] VARCHAR(100) DEFAULT ' '," +  // 直角边最小值
                                    $"[VerticalAngleMax] VARCHAR(100) DEFAULT ' '," + // 垂直度最大值
                                    $"[VerticalAngleMin] VARCHAR(100) DEFAULT ' '," + // 垂直度最小值
                                    $"[LeftTopCharmfer] VARCHAR(100) DEFAULT ' '," +   // 左上倒角
                                    $"[RightTopCharmfer] VARCHAR(100) DEFAULT ' '," + // 右上倒角
                                    $"[LeftBottomCharmfer] VARCHAR(100) DEFAULT ' '," + // 左下倒角
                                    $"[RightBottomCharmfer] VARCHAR(100) DEFAULT ' '," + // 右下倒角
                                    $"[LeftTopAngle] VARCHAR(100) DEFAULT ' '," + // 左上角度
                                    $"[RightTopAngle] VARCHAR(100) DEFAULT ' '," + // 右上角度
                                    $"[LeftBottomAngle] VARCHAR(100) DEFAULT ' '," + // 左下角度
                                    $"[RightBottomAngle] VARCHAR(100) DEFAULT ' '," +      // 右下角度
                                    $"[LengthXMax] VARCHAR(100) DEFAULT ' '," +      // X边长最大值
                                    $"[LengthXMin] VARCHAR(100) DEFAULT ' '," +      // X边长最小值
                                    $"[LengthYMax] VARCHAR(100) DEFAULT ' '," +      // Y边长最大值
                                    $"[LengthYMin] VARCHAR(100) DEFAULT ' '," +      // Y边长最小值
                                    $"[FrontEdgeBreakExist] VARCHAR(100) DEFAULT ' '," + // 前崩边有无
                                    $"[FrontEdgeBreakNum] VARCHAR(100) DEFAULT ' '," + // 前崩边数量
                                    $"[FrontEdgeBreakArea] VARCHAR(100) DEFAULT ' '," + // 前崩边面积
                                    $"[BackEdgeBreakExist] VARCHAR(100) DEFAULT ' '," + // 后崩边有无
                                    $"[BackEdgeBreakNum] VARCHAR(100) DEFAULT ' '," + // 后崩边数量
                                    $"[BackEdgeBreakArea] VARCHAR(100) DEFAULT ' '," + // 后崩边面积
                                    $"[LeftEdgeBreakExist] VARCHAR(100) DEFAULT ' '," + // 左崩边有无
                                    $"[LeftEdgeBreakNum] VARCHAR(100) DEFAULT ' '," + // 左崩边数量
                                    $"[LeftSurfaceBreakExist] VARCHAR(100) DEFAULT ' '," + // 左表崩有无
                                    $"[LeftSurfaceBreakNum] VARCHAR(100) DEFAULT ' '," + // 左表崩数量
                                    $"[RightEdgeBreakExist] VARCHAR(100) DEFAULT ' '," + // 右崩边有无
                                    $"[RightEdgeBreakNum] VARCHAR(100) DEFAULT ' '," + // 右崩边数量
                                    $"[RightSurfaceBreakExist] VARCHAR(100) DEFAULT ' '," + // 右表崩有无
                                    $"[RightSurfaceBreakNum] VARCHAR(100) DEFAULT ' '," + // 右表崩数量
                                    $"[SumdgeUpExist] VARCHAR(100) DEFAULT ' '," + // 上脏污有无
                                    $"[SmudgeUpArea] VARCHAR(100) DEFAULT ' '," + // 上脏污面积
                                    $"[SumdgeUpNum] VARCHAR(100) DEFAULT ' '," + // 上脏污数量
                                    $"[SumdgeUpReverse] VARCHAR(100) DEFAULT ' '," + // 上脏污是否反向
                                    $"[SumdgeUpHoleExist] VARCHAR(100) DEFAULT ' '," + // 上脏污穿孔有无
                                    $"[SumdgeUpHoleNum] VARCHAR(100) DEFAULT ' '," + // 上脏污穿孔数量
                                    $"[HoleExistUp] VARCHAR(100) DEFAULT ' '," + // 上脏污缺口
                                    $"[HoleNumUp] VARCHAR(100) DEFAULT ' '," + // 上脏污缺口数量
                                     $"[SumdgeDownExist] VARCHAR(100) DEFAULT ' '," + // 下脏污有无
                                    $"[SumdgeDownArea] VARCHAR(100) DEFAULT ' '," + // 下脏污面积
                                    $"[SumdgeDownNum] VARCHAR(100) DEFAULT ' '," + // 下脏污数量
                                    $"[SumdgeDownReverse] VARCHAR(100) DEFAULT ' '," + // 下脏污是否反向
                                    $"[SumdgeDownHoleExist] VARCHAR(100) DEFAULT ' '," + // 下脏污穿孔有无
                                    $"[SumdgeDownHoleNum] VARCHAR(100) DEFAULT ' '," + // 下脏污穿孔数量
                                    $"[HoleExistDown] VARCHAR(100) DEFAULT ' '," + // 下脏污缺口有无
                                    $"[HoleNumDown] VARCHAR(100) DEFAULT ' '," + // 下脏污孔洞数量
                                    $"[SubfissureExist01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_隐裂有无
                                    $"[SubfissureArea01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_隐裂面积
                                    $"[SubfissureNum01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_隐裂数量
                                    $"[SubfissureBreakExist01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_崩边有无
                                    $"[SubfissureBreakArea01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_崩边面积
                                    $"[SubfissureBreakNum01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_崩边数量
                                    $"[SubfissureHoleExist01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_孔洞有无
                                    $"[SubfissureHoleNum01] VARCHAR(100) DEFAULT ' '," + // 隐裂1_孔洞数量
                                    $"[SubfissureExist02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_隐裂有无
                                    $"[SubfissureArea02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_隐裂面积
                                    $"[SubfissureNum02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_隐裂数量
                                    $"[SubfissureBreakExist02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_崩边有无
                                    $"[SubfissureBreakArea02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_崩边面积
                                    $"[SubfissureBreakNum02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_崩边数量
                                    $"[SubfissureHoleExist02] VARCHAR(100) DEFAULT ' '," + // 隐裂2_孔洞有无
                                    $"[SubfissureHoleNum02] VARCHAR(100) DEFAULT ' ');" + // 隐裂2_孔洞数量
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入十条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO {tableName} (DetectedTime,ProductionDate, WaferId, CutNumber, CrystalNumber, PositionNumber, ProductionLot, FlowerNumber, DetectionRecipe, DetectedLevel, LevelType, " +
                        $"TypeDescription, BoxNumber, ThicknessAver, TTV, LineTraceMax, Warping, ThicknessMin, ThicknessMax, IsDenseLine, LineTraceUpNum, LineTraceUpMax," +
                        $" LineTraceDownNum, LineTraceDownMax, LineTraceCount, ResistivityAver, ResistivityMax, ResistivityMin, LengthMax, LengthMin, LengthX, LengthY, DiagonalLeftStart, " +
                        $"DialonalRightStart, ChamferMax, ChamferMin, UpDownParallel, LeftRightParallel, SquareLineMax, SquareLineMin, VerticalAngleMax, VerticalAngleMin, LeftTopCharmfer, " +
                        $"RightTopCharmfer, LeftBottomCharmfer, RightBottomCharmfer, LeftTopAngle, RightTopAngle, LeftBottomAngle, RightBottomAngle,LengthXMax,LengthXMin,LengthYMax,LengthYMin," +
                        $"FrontEdgeBreakExist, FrontEdgeBreakNum, FrontEdgeBreakArea," +
                        $"BackEdgeBreakExist, BackEdgeBreakNum, BackEdgeBreakArea,LeftEdgeBreakExist, LeftEdgeBreakNum, LeftSurfaceBreakNum, LeftSurfaceBreakExist, RightEdgeBreakExist, " +
                        $"RightEdgeBreakNum, RightSurfaceBreakNum, " +
                        $"RightSurfaceBreakExist,SumdgeUpExist,SmudgeUpArea,SumdgeUpNum,SumdgeUpReverse,SumdgeUpHoleExist,SumdgeUpHoleNum,HoleExistUp,HoleNumUp,SumdgeDownExist," +
                        $"SumdgeDownArea,SumdgeDownNum,SumdgeDownReverse,SumdgeDownHoleExist,SumdgeDownHoleNum,HoleExistDown,HoleNumDown, SubfissureArea01, " +
                        $"SubfissureNum01, SubfissureExist01, SubfissureBreakArea01, SubfissureBreakNum01, SubfissureBreakExist01, SubfissureHoleNum01, SubfissureHoleExist01, SubfissureArea02, " +
                        $"SubfissureNum02, SubfissureExist02, SubfissureBreakArea02, SubfissureBreakNum02, SubfissureBreakExist02, SubfissureHoleNum02, SubfissureHoleExist02) " +
                        $"VALUES (@DetectedTime,@ProductionDate, @WaferId, @CutNumber, @CrystalNumber, @PositionNumber, @ProductionLot, @FlowerNumber, @DetectionRecipe, @DetectedLevel, @LevelType, " +
                        $"@TypeDescription, @BoxNumber, @ThicknessAver, @TTV, @LineTraceMax, @Warping, @ThicknessMin, @ThicknessMax, @IsDenseLine, @LineTraceUpNum, @LineTraceUpMax, " +
                        $"@LineTraceDownNum, @LineTraceDownMax, @LineTraceCount, @ResistivityAver, @ResistivityMax, @ResistivityMin, @LengthMax, @LengthMin, @LengthX, @LengthY, @DiagonalLeftStart, " +
                        $"@DialonalRightStart, @ChamferMax, @ChamferMin, @UpDownParallel, @LeftRightParallel, @SquareLineMax, @SquareLineMin, @VerticalAngleMax, @VerticalAngleMin, @LeftTopCharmfer, " +
                        $"@RightTopCharmfer, @LeftBottomCharmfer, @RightBottomCharmfer, @LeftTopAngle, @RightTopAngle, @LeftBottomAngle, @RightBottomAngle,@LengthXMax,@LengthXMin,@LengthYMax,@LengthYMin," +
                        $" @FrontEdgeBreakExist, @FrontEdgeBreakNum, @FrontEdgeBreakArea," +
                        $"@BackEdgeBreakExist, @BackEdgeBreakNum,@BackEdgeBreakArea, @LeftEdgeBreakExist, @LeftEdgeBreakNum, @LeftSurfaceBreakNum, @LeftSurfaceBreakExist, @RightEdgeBreakExist," +
                        $" @RightEdgeBreakNum, @RightSurfaceBreakNum," +
                        $"@RightSurfaceBreakExist, " +
                        $"@SumdgeUpExist,@SmudgeUpArea,@SumdgeUpNum,@SumdgeUpReverse,@SumdgeUpHoleExist,@SumdgeUpHoleNum,@HoleExistUp,@HoleNumUp," +
                        $"@SumdgeDownExist,@SumdgeDownArea,@SumdgeDownNum,@SumdgeDownReverse,@SumdgeDownHoleExist,@SumdgeDownHoleNum,@HoleExistDown,@HoleNumDown," +
                        $" @SubfissureArea01, @SubfissureNum01, " +
                        $"@SubfissureExist01, @SubfissureBreakArea01, @SubfissureBreakNum01, @SubfissureBreakExist01, @SubfissureHoleNum01, @SubfissureHoleExist01, @SubfissureArea02, @SubfissureNum02, " +
                        $"@SubfissureExist02, @SubfissureBreakArea02, @SubfissureBreakNum02, @SubfissureBreakExist02, @SubfissureHoleNum02, @SubfissureHoleExist02);";

                    int waferIdStart = 10000;
                    for (int i = 0; i < 0; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@DetectedTime", SqlDbType.VarChar) { Value = DateTimeHelper.GetTimeNowForSql() },
                            new SqlParameter("@ProductionDate",SqlDbType.VarChar){Value = DateTimeHelper.GetProductionDatetime()},
                            new SqlParameter("@WaferId", SqlDbType.VarChar) { Value = (waferIdStart+i).ToString() },
                            new SqlParameter("@CutNumber", SqlDbType.VarChar) { Value = "TestCrystal007"},
                            new SqlParameter("@CrystalNumber", SqlDbType.VarChar) { Value = "TestCrystal007" },
                            new SqlParameter("@PositionNumber", SqlDbType.VarChar) { Value =i.ToString()},
                            new SqlParameter("@ProductionLot", SqlDbType.VarChar) { Value = "123"},
                            new SqlParameter("@FlowerNumber", SqlDbType.VarChar) { Value = "123" },
                            new SqlParameter("@DetectionRecipe", SqlDbType.VarChar) { Value =GlobalValues.ProductionRecipeName },
                            new SqlParameter("@DetectedLevel", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LevelType", SqlDbType.VarChar) { Value = $"{i}级" },
                            new SqlParameter("@TypeDescription", SqlDbType.VarChar) { Value = $"等级{i}描述" },
                            new SqlParameter("@BoxNumber", SqlDbType.VarChar) { Value = $"{i+100}" },
                            new SqlParameter("@ThicknessAver", SqlDbType.VarChar) { Value = (i+30).ToString()},
                            new SqlParameter("@TTV", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LineTraceMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@Warping", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ThicknessMin", SqlDbType.VarChar) { Value = $"{i+10}" },
                            new SqlParameter("@ThicknessMax", SqlDbType.VarChar) { Value = (i+30).ToString()},
                            new SqlParameter("@IsDenseLine", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@LineTraceUpNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LineTraceUpMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LineTraceDownNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LineTraceDownMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LineTraceCount", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ResistivityAver", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ResistivityMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ResistivityMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthX", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthY", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@DiagonalLeftStart", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@DialonalRightStart", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ChamferMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@ChamferMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@UpDownParallel", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftRightParallel", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SquareLineMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SquareLineMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@VerticalAngleMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@VerticalAngleMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftTopCharmfer", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightTopCharmfer", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftBottomCharmfer", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightBottomCharmfer", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftTopAngle", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightTopAngle", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftBottomAngle", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightBottomAngle", SqlDbType.VarChar) { Value = i.ToString() },

                            new SqlParameter("@LengthXMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthXMin", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthYMax", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LengthYMin", SqlDbType.VarChar) { Value = i.ToString() },

                            new SqlParameter("@FrontEdgeBreakExist", SqlDbType.VarChar) { Value ="0"  },
                            new SqlParameter("@FrontEdgeBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@FrontEdgeBreakArea", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@BackEdgeBreakExist", SqlDbType.VarChar) { Value = "0"},
                            new SqlParameter("@BackEdgeBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@BackEdgeBreakArea", SqlDbType.VarChar) { Value = i.ToString() },

                            new SqlParameter("@LeftEdgeBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftEdgeBreakExist", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@LeftSurfaceBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@LeftSurfaceBreakExist", SqlDbType.VarChar) { Value = "0"},
                            new SqlParameter("@RightEdgeBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightEdgeBreakExist", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@RightSurfaceBreakNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@RightSurfaceBreakExist", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SumdgeUpExist", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SmudgeUpArea", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeUpNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeUpReverse",SqlDbType.VarChar){Value = "0" },
                            new SqlParameter("@SumdgeUpHoleExist", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SumdgeUpHoleNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@HoleExistUp", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@HoleNumUp", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeDownExist", SqlDbType.VarChar) { Value ="0" },
                            new SqlParameter("@SumdgeDownArea", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeDownNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeDownReverse",SqlDbType.VarChar){Value = "0"},
                            new SqlParameter("@SumdgeDownHoleExist", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SumdgeDownHoleNum", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@HoleExistDown", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@HoleNumDown", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureArea01", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureNum01", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureExist01", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SubfissureBreakArea01", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureBreakNum01", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureBreakExist01", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SubfissureHoleNum01", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureHoleExist01", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SubfissureArea02", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureNum02", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureExist02", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SubfissureBreakArea02", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureBreakNum02", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureBreakExist02", SqlDbType.VarChar) { Value = "0" },
                            new SqlParameter("@SubfissureHoleNum02", SqlDbType.VarChar) { Value = i.ToString() },
                            new SqlParameter("@SubfissureHoleExist02", SqlDbType.VarChar) { Value = i.ToString() },
                        };
                        //这里插入数据是用来测试,正常生产部需要插入数据.
                        int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        if (ret <= 0)
                        {
                            infoMessage = $"数据表{tableName} 插入数据失败!";
                            throw new Exception(infoMessage);
                        }
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }




        /// <summary>
        /// 创建检测类型表和检测的晶棒编号一一对应.如果其对应的工单文件找不到的情况下.使用这个.
        /// 如果程序在加载的时候,工单的配置文件已经存在,优先从配置文件中去加载.
        /// 这其实就是个样本,创建这个样本的原因是什么? 先不创建,先放到这里.
        /// 我想了一下,这个数据库没有必要存在,保证D盘有的DefaultTestRecipe文件就行.
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateDetectedLevelTable()
        {
            string tableName = TableNames.DetectedLevelTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[DetectedRecipe] VARCHAR(100)," +
                                    $"[Level] VARCHAR(20) NOT NULL," +
                                    $"[IsUsed] bit NOT NULL," +
                                    $"[LevelType] VARCHAR(20) NOT NULL," +
                                    $"[TypeDescription] VARCHAR(100) NOT NULL," +
                                    $"[BoxesInto] VARCHAR(100) NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入几条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([DetectedRecipe], [Level],[IsUsed],[LevelType],[TypeDescription],[Level],[BoxesInto]) " +
                        $"VALUES (@DetectedRecipe1,@Level1,@IsUsed1,@LevelType1,TypeDescription1,Level1,BoxesInto1)," +
                        $"(@DetectedRecipe2,@Level2,@IsUsed2,@LevelType2,TypeDescription2,Level2,BoxesInto2)," +
                        $"(@DetectedRecipe3,@Level3,@IsUsed3,@LevelType3,TypeDescription3,Level3,BoxesInto3)," +
                        $"(@DetectedRecipe4,@Level4,@IsUsed4,@LevelType4,TypeDescription4,Level4,BoxesInto4)," +
                        $"(@DetectedRecipe5,@Level5,@IsUsed5,@LevelType5,TypeDescription5,Level5,BoxesInto5)," +
                        $"(@DetectedRecipe6,@Level6,@IsUsed6,@LevelType6,TypeDescription6,Level6,BoxesInto6)," +
                        $"(@DetectedRecipe7,@Level7,@IsUsed7,@LevelType7,TypeDescription7,Level7,BoxesInto7)," +
                        $"(@DetectedRecipe8,@Level8,@IsUsed8,@LevelType8,TypeDescription8,Level8,BoxesInto8)," +
                        $"(@DetectedRecipe9,@Level9,@IsUsed9,@LevelType9,TypeDescription9,Level9,BoxesInto9)," +
                        $"(@DetectedRecipe10,@Level10,@IsUsed10,@LevelType10,TypeDescription10,Level10,BoxesInto10)," +
                        $"(@DetectedRecipe1,@Level1,@IsUsed1,@LevelType1,TypeDescription1,Level1,BoxesInto1)," +
                        $"(@DetectedRecipe1,@Level1,@IsUsed1,@LevelType1,TypeDescription1,Level1,BoxesInto1)," +
                        $"(@DetectedRecipe1,@Level1,@IsUsed1,@LevelType1,TypeDescription1,Level1,BoxesInto1)," +
                        $"(@DetectedRecipe1,@Level1,@IsUsed1,@LevelType1,TypeDescription1,Level1,BoxesInto1);";
                    SqlParameter[] parameters = new SqlParameter[]
                    {
                        new SqlParameter("@SlaveName1",SqlDbType.VarChar){Value = "1. 电阻率"},
                        new SqlParameter("@SlaveIp1",SqlDbType.VarChar){Value = "192.168.3.101"},
                        new SqlParameter("@SlavePort1",SqlDbType.Int){Value= 50001},

                        new SqlParameter("@SlaveName2",SqlDbType.VarChar){Value = "2. 尺寸"},
                        new SqlParameter("@SlaveIp2",SqlDbType.VarChar){Value = "192.168.3.102"},
                        new SqlParameter("@SlavePort2",SqlDbType.Int){Value= 50002},

                        new SqlParameter("@SlaveName3",SqlDbType.VarChar){Value = "3. 崩边"},
                        new SqlParameter("@SlaveIp3",SqlDbType.VarChar){Value = "192.168.3.103"},
                        new SqlParameter("@SlavePort3",SqlDbType.Int){Value= 50003},

                        new SqlParameter("@SlaveName4",SqlDbType.VarChar){Value = "4. 3D"},
                        new SqlParameter("@SlaveIp4",SqlDbType.VarChar){Value = "192.168.3.104"},
                        new SqlParameter("@SlavePort4",SqlDbType.Int){Value= 50004},

                        new SqlParameter("@SlaveName5",SqlDbType.VarChar){Value = "5. 脏污"},
                        new SqlParameter("@SlaveIp5",SqlDbType.VarChar){Value = "192.168.3.105"},
                        new SqlParameter("@SlavePort5",SqlDbType.Int){Value= 50005},

                        new SqlParameter("@SlaveName6",SqlDbType.VarChar){Value = "6. 隐裂"},
                        new SqlParameter("@SlaveIp6",SqlDbType.VarChar){Value = "192.168.3.106"},
                        new SqlParameter("@SlavePort6",SqlDbType.Int){Value= 50006},
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }

        /// <summary>
        /// 晶棒结果信息统计表,晶棒编号对应的等级数量统计表.
        /// </summary>
        /// <exception cref="Exception"></exception>
        private static void CreateCrystalResultRecordTable()
        {
            string tableName = TableNames.CrystalRecordTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[CrystalNumber] Varchar(200) NOT NULL," +
                                    $"[ProductionDate] VARCHAR(20)," +
                                    $"[Lv01] VARCHAR(50) ," +
                                    $"[Lv02] VARCHAR(50)," +
                                    $"[Lv03] VARCHAR(50) ," +
                                    $"[Lv04] VARCHAR(50)," +
                                    $"[Lv05] VARCHAR(50) ," +
                                    $"[Lv06] VARCHAR(50)," +
                                    $"[Lv07] VARCHAR(50) ," +
                                    $"[Lv08] VARCHAR(50)," +
                                    $"[Lv09] VARCHAR(50) ," +
                                    $"[Lv10] VARCHAR(50)," +
                                    $"[Lv11] VARCHAR(50) ," +
                                    $"[Lv12] VARCHAR(50)," +
                                    $"[Lv13] VARCHAR(50) ," +
                                    $"[Lv14] VARCHAR(50) ," +
                                    $"[Lv15] VARCHAR(50) ," +
                                    $"[Lv16] VARCHAR(50) ," +
                                    $"[Lv17] VARCHAR(50) ," +
                                    $"[Lv18] VARCHAR(50) ," +
                                    $"[Lv19] VARCHAR(50) ," +
                                    $"[Lv20] VARCHAR(50) ," +
                                    $"[Lv21] VARCHAR(50) ," +
                                    $"[Lv22] VARCHAR(50) ," +
                                    $"[Lv23] VARCHAR(50) ," +
                                    $"[Lv24] VARCHAR(50) ," +
                                    $"[Lv25] VARCHAR(50) ," +
                                    $"[Lv26] VARCHAR(50));" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入一条数据(admin hdno1管理员)
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入一条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([CrystalNumber], [ProductionDate],[Lv01],[Lv02],[Lv03],[Lv04],[Lv05],[Lv06],[Lv07],[Lv08],[Lv09],[Lv10],[Lv11]," +
                        $"[Lv12],[Lv13],[Lv14],[Lv15],[Lv16],[Lv17],[Lv18],[Lv19],[Lv20],[Lv21],[Lv22],[Lv23],[Lv24],[Lv25],[Lv26]) " +
                        $"VALUES (@CrystalNumber,@ProductionDate,@Lv01,@Lv02,@Lv03,@Lv04,@Lv05,@Lv06,@Lv07,@Lv08,@Lv09,@Lv10,@Lv11,@Lv12,@Lv13,@Lv14,@Lv15," +
                        $"@Lv16,@Lv17,@Lv18,@Lv19,@Lv20,@Lv21,@Lv22,@Lv23,@Lv24,@Lv25,@Lv26);";

                    for (int i = 0; i < 1; i++)
                    {
                        SqlParameter[] parameters = new SqlParameter[]
                        {
                            new SqlParameter("@CrystalNumber",SqlDbType.Int){Value = i},
                            new SqlParameter("@ProductionDate",SqlDbType.VarChar){Value = DateTimeHelper.GetTimeNowForSql()},
                            new SqlParameter("@Lv01",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv02",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv03",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv04",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv05",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv06",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv07",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv08",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv09",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv10",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv11",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv12",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv13",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv14",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv15",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv16",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv17",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv18",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv19",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv20",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv21",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv22",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv23",SqlDbType.VarChar){Value="3"},
                            new SqlParameter("@Lv24",SqlDbType.VarChar){Value= "4"},
                            new SqlParameter("@Lv25",SqlDbType.VarChar){Value= "2"},
                            new SqlParameter("@Lv26",SqlDbType.VarChar){Value= "2"},
                        };
                        //int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                        //if (ret <= 0)
                        //{
                        //    infoMessage = $"数据表{tableName} 插入数据失败!";
                        //    throw new Exception(infoMessage);
                        //}
                    }
                    infoMessage = $"数据表{tableName} 插入数据表成功!";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }


        private static void CreateVisionOffsetTable()
        {
            string tableName = TableNames.VisionOffsetTb;
            try
            {
                /*
                 * 1. N'[dbo].[{tableName}]'和N'U'中的N：这是SQL Server中表示Unicode字符串的前缀。在SQL Server中，
                 * Unicode字符串必须以N为前缀。如果没有N，那么字符串就会被当作非Unicode字符串处理，
                 * 这可能会导致某些Unicode字符无法正确处理。
                 *
                 * 2. type in (N'U')：这是一个判断语句，sys.objects表中的type字段代表了对象的类型。
                 * 在这里U代表用户表(用户创建的表)，因此type in (N'U')意味着在所有的用户表中查找。
                 */
                string sql = $"IF NOT EXISTS(SELECT* FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[{tableName}]') AND type in (N'U'))" +
                                    $"BEGIN " +
                                    $"CREATE TABLE[dbo].[{tableName}](" +
                                    $"[Id] INT IDENTITY(1,1) PRIMARY KEY," +
                                    $"[ModuleName] VARCHAR(100)," +
                                    $"[OptionName] VARCHAR(100)," +
                                    $"[OffsetK] float NOT NULL," +
                                    $"[OffsetB] float NOT NULL);" +
                                    $" END";
                SqlHelper.ExecuteNonQuery(sql, null);
                // 如果数据表为空,就插入默认数据
                sql = $"Select * from [{tableName}]";
                int count = SqlHelper.ExcuteGetCount(sql, null);
                if (count <= 0)
                {
                    string infoMessage = $"数据表{tableName} 创建成功,并且插入几条默认的测试数据";
                    LogHelper.WriteLog(LogType.Info, infoMessage);
                    sql = $"INSERT INTO [DBO].{tableName} ([ModuleName], [OptionName],[OffsetK],[OffsetB]) " +
                        $"VALUES (@ModuleName1,@OptionName1,@OffsetK1,@OffsetB1), (@ModuleName2,@OptionName2,@OffsetK2,@OffsetB2), (@ModuleName3,@OptionName3,@OffsetK3,@OffsetB3)," +
                        $"(@ModuleName4,@OptionName4,@OffsetK4,@OffsetB4),(@ModuleName5,@OptionName5,@OffsetK5,@OffsetB5),(@ModuleName6,@OptionName6,@OffsetK6,@OffsetB6)," +
                        $" (@ModuleName7,@OptionName7,@OffsetK7,@OffsetB7), (@ModuleName8,@OptionName8,@OffsetK8,@OffsetB8), (@ModuleName9,@OptionName9,@OffsetK9,@OffsetB9)," +
                        $"  (@ModuleName10,@OptionName10,@OffsetK10,@OffsetB10), (@ModuleName11,@OptionName11,@OffsetK11,@OffsetB11), (@ModuleName12,@OptionName12,@OffsetK12,@OffsetB12)," +
                        $" (@ModuleName13,@OptionName13,@OffsetK13,@OffsetB13), (@ModuleName14,@OptionName14,@OffsetK14,@OffsetB14), " +
                        $"(@ModuleName15,@OptionName15,@OffsetK15,@OffsetB15)," +
                        $"(@ModuleName16,@OptionName16,@OffsetK16,@OffsetB16)," +
                        $"(@ModuleName17,@OptionName17,@OffsetK17,@OffsetB17)," +
                        $"(@ModuleName18,@OptionName18,@OffsetK18,@OffsetB18)," +
                        $"(@ModuleName19,@OptionName19,@OffsetK19,@OffsetB19)," +
                        $"(@ModuleName20,@OptionName20,@OffsetK20,@OffsetB20)," +
                        $"(@ModuleName22,@OptionName22,@OffsetK22,@OffsetB22)," +
                        $"(@ModuleName23,@OptionName23,@OffsetK23,@OffsetB23)," +
                        $"(@ModuleName24,@OptionName24,@OffsetK24,@OffsetB24)," +
                        $"(@ModuleName25,@OptionName25,@OffsetK25,@OffsetB25)," +
                        $"(@ModuleName26,@OptionName26,@OffsetK26,@OffsetB26)," +
                        $"(@ModuleName27,@OptionName27,@OffsetK27,@OffsetB27)," +
                        $"(@ModuleName28,@OptionName28,@OffsetK28,@OffsetB28)," +
                        $"(@ModuleName29,@OptionName29,@OffsetK29,@OffsetB29)," +
                        $"(@ModuleName30,@OptionName30,@OffsetK30,@OffsetB30)," +
                        $"(@ModuleName31,@OptionName31,@OffsetK31,@OffsetB31)," +
                        $"(@ModuleName32,@OptionName32,@OffsetK32,@OffsetB32)," +
                        $"(@ModuleName33,@OptionName33,@OffsetK33,@OffsetB33)," +
                        $" (@ModuleName34,@OptionName34,@OffsetK34,@OffsetB34), (@ModuleName35,@OptionName35,@OffsetK35,@OffsetB35)," +
                        $" (@ModuleName36,@OptionName36,@OffsetK36,@OffsetB36), (@ModuleName37,@OptionName37,@OffsetK37,@OffsetB37)," +
                        $" (@ModuleName38,@OptionName38,@OffsetK38,@OffsetB38), (@ModuleName39,@OptionName39,@OffsetK39,@OffsetB39)," +
                        $" (@ModuleName40,@OptionName40,@OffsetK40,@OffsetB40);";

                    SqlParameter[] parameters = new SqlParameter[]
                    {
                       new SqlParameter("@ModuleName1",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName1",SqlDbType.VarChar){Value="平均厚度" },
                       new SqlParameter("@OffsetK1",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB1",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName2",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName2",SqlDbType.VarChar){Value="TTV" },
                       new SqlParameter("@OffsetK2",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB2",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName3",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName3",SqlDbType.VarChar){Value="线痕最大值" },
                       new SqlParameter("@OffsetK3",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB3",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName4",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName4",SqlDbType.VarChar){Value="翘曲" },
                       new SqlParameter("@OffsetK4",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB4",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName5",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName5",SqlDbType.VarChar){Value="最小厚度" },
                       new SqlParameter("@OffsetK5",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB5",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName6",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName6",SqlDbType.VarChar){Value="最大厚度" },
                       new SqlParameter("@OffsetK6",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB6",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName7",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName7",SqlDbType.VarChar){Value="是否密集线痕" },
                       new SqlParameter("@OffsetK7",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB7",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName8",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName8",SqlDbType.VarChar){Value="上线痕数量" },
                       new SqlParameter("@OffsetK8",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB8",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName9",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName9",SqlDbType.VarChar){Value="上线痕数量最大值" },
                       new SqlParameter("@OffsetK9",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB9",SqlDbType.Float){Value = 0},

                      new SqlParameter("@ModuleName10",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName10",SqlDbType.VarChar){Value="下线痕数量" },
                       new SqlParameter("@OffsetK10",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB10",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName11",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName11",SqlDbType.VarChar){Value="下线痕数量最大值" },
                       new SqlParameter("@OffsetK11",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB11",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName12",SqlDbType.VarChar){Value = "3D线激光测量"},
                       new SqlParameter("@OptionName12",SqlDbType.VarChar){Value="线痕数量" },
                       new SqlParameter("@OffsetK12",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB12",SqlDbType.Float){Value = 0},

                       // 尺寸补偿
                       new SqlParameter("@ModuleName13",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName13",SqlDbType.VarChar){Value="边长最大值" },
                       new SqlParameter("@OffsetK13",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB13",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName14",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName14",SqlDbType.VarChar){Value="边长最小值" },
                       new SqlParameter("@OffsetK14",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB14",SqlDbType.Float){Value = 0},

                        new SqlParameter("@ModuleName15",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName15",SqlDbType.VarChar){Value="X边长" },
                       new SqlParameter("@OffsetK15",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB15",SqlDbType.Float){Value = 0},

                        new SqlParameter("@ModuleName16",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName16",SqlDbType.VarChar){Value="Y边长" },
                       new SqlParameter("@OffsetK16",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB16",SqlDbType.Float){Value = 0},

                        new SqlParameter("@ModuleName17",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName17",SqlDbType.VarChar){Value="对角线左上右下" },
                       new SqlParameter("@OffsetK17",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB17",SqlDbType.Float){Value = 0},

                        new SqlParameter("@ModuleName18",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName18",SqlDbType.VarChar){Value="对角线右上左下" },
                       new SqlParameter("@OffsetK18",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB18",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName19",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName19",SqlDbType.VarChar){Value="倒角最大值" },
                       new SqlParameter("@OffsetK19",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB19",SqlDbType.Float){Value = 0},


                       new SqlParameter("@ModuleName20",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName20",SqlDbType.VarChar){Value="倒角最小值" },
                       new SqlParameter("@OffsetK20",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB20",SqlDbType.Float){Value = 0},




                       new SqlParameter("@ModuleName22",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName22",SqlDbType.VarChar){Value="上下平行度" },
                       new SqlParameter("@OffsetK22",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB22",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName23",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName23",SqlDbType.VarChar){Value="左右平行度" },
                       new SqlParameter("@OffsetK23",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB23",SqlDbType.Float){Value = 0},


                       new SqlParameter("@ModuleName24",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName24",SqlDbType.VarChar){Value="直角边最大值" },
                       new SqlParameter("@OffsetK24",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB24",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName25",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName25",SqlDbType.VarChar){Value="直角边最小值" },
                       new SqlParameter("@OffsetK25",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB25",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName26",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName26",SqlDbType.VarChar){Value="垂直度最大值" },
                       new SqlParameter("@OffsetK26",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB26",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName27",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName27",SqlDbType.VarChar){Value="垂直度最小值" },
                       new SqlParameter("@OffsetK27",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB27",SqlDbType.Float){Value = 0},


                       new SqlParameter("@ModuleName28",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName28",SqlDbType.VarChar){Value="左上倒角" },
                       new SqlParameter("@OffsetK28",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB28",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName29",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName29",SqlDbType.VarChar){Value="右上倒角" },
                       new SqlParameter("@OffsetK29",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB29",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName30",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName30",SqlDbType.VarChar){Value="左下倒角" },
                       new SqlParameter("@OffsetK30",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB30",SqlDbType.Float){Value = 0},


                       new SqlParameter("@ModuleName31",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName31",SqlDbType.VarChar){Value="右下倒角" },
                       new SqlParameter("@OffsetK31",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB31",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName32",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName32",SqlDbType.VarChar){Value="左上角度" },
                       new SqlParameter("@OffsetK32",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB32",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName33",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName33",SqlDbType.VarChar){Value="右上角度" },
                       new SqlParameter("@OffsetK33",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB33",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName34",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName34",SqlDbType.VarChar){Value="左下角度" },
                       new SqlParameter("@OffsetK34",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB34",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName35",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName35",SqlDbType.VarChar){Value="右下角度" },
                       new SqlParameter("@OffsetK35",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB35",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName36",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName36",SqlDbType.VarChar){Value="X边长最大值" },
                       new SqlParameter("@OffsetK36",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB36",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName37",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName37",SqlDbType.VarChar){Value="X边长最小值" },
                       new SqlParameter("@OffsetK37",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB37",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName38",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName38",SqlDbType.VarChar){Value="Y边长最大值" },
                       new SqlParameter("@OffsetK38",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB38",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName39",SqlDbType.VarChar){Value = "尺寸"},
                       new SqlParameter("@OptionName39",SqlDbType.VarChar){Value="Y边长最小值" },
                       new SqlParameter("@OffsetK39",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB39",SqlDbType.Float){Value = 0},

                       new SqlParameter("@ModuleName40",SqlDbType.VarChar){Value = "电阻率"},
                       new SqlParameter("@OptionName40",SqlDbType.VarChar){Value="电阻率值" },
                       new SqlParameter("@OffsetK40",SqlDbType.Float){Value=1},
                       new SqlParameter("@OffsetB40",SqlDbType.Float){Value = 0},
                    };
                    int ret = SqlHelper.ExecuteNonQuery(sql, parameters);
                    if (ret <= 0)
                    {
                        infoMessage = $"数据表{tableName} 插入数据失败!";
                        throw new Exception(infoMessage);
                    }
                    else
                    {
                        infoMessage = $"数据表{tableName} 插入数据表成功!";
                        LogHelper.WriteLog(LogType.Info, infoMessage);
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogType.Info, $"{tableName} 数据表已经存在,并且至少有一条数据");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{tableName} 数据表创建失败: {ex.Message}");
            }
        }
    }
}
